CREATE TABLE "InventoryIssuedStockHeader" (
	"InventoryIssuedStockHeaderId" bigserial primary key,
	"IssuedDate" timestamp NULL,
	"IssuedBy" int4 NULL,
	"HandOverTo" int4 NULL,
	"Comment" text NULL,
	"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId"),
	"ReceivedBy" int4 NULL,
	"ReceivedDate" timestamp NULL,
	"IssueHeaderId" int4 null references "IssueHeader"("IssueHeaderId"),
	"IssueNumber" text NULL
	);
	
CREATE TABLE "InventoryIssuedStockDetail" (
	"InventoryIssuedStockDetailId" bigserial primary key,
	"InventoryIssuedStockHeaderId" int8 references "InventoryIssuedStockHeader"("InventoryIssuedStockHeaderId"),
	"InventoryProductId" int4 references "InventoryProduct"("InventoryProductId"),
	"TaxId" int4 NULL,
	"QuantityIn" int4 NULL,
	"BatchNumber" varchar(50) NULL,
	"ExpiryDate" date NULL,
	"PurchaseRate" numeric(8, 2) NULL,
	"InventoryStockId" int4 null references "InventoryStock"("InventoryStockId")
	);

CREATE TABLE "InventoryProductRack" (
	"InventoryProductRackId" serial primary key,
	"RackName" text NULL,
	"CreatedBy" int4 NULL,
	"CreatedDate" timestamp NULL,
	"ModifiedBy" int4 NULL,
	"ModifiedDate" timestamp NULL,
	"InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId"),
	"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId")
);

CREATE TABLE "InventoryProductDetail" (
	"InventoryProductDetailId" serial primary key,
	"InventoryProductRackId" int references "InventoryProductRack"("InventoryProductRackId"),
	"ROQ" int4 NULL,
	"ROL" int4 NULL,
	"InventoryProductId" int4  references "InventoryProduct"("InventoryProductId"),
	"InventoryDepartmentId" int references "InventoryDepartment"("InventoryDepartmentId"),
	"InventoryWareHouseId" int references "InventoryWareHouse"("InventoryWareHouseId"),
	"CreatedBy" int4 NULL,
	"CreatedDate" timestamp NULL,
	"ModifiedBy" int4 NULL,
	"ModifiedDate" timestamp null
);

CREATE TABLE "InventoryDepartmentConsumption" (
	"InventoryDepartmentConsumptionId" serial primary key,
	"InventoryDepartmentalStockId" int references "InventoryDepartmentalStock"("InventoryDepartmentalStockId"),
	"QuantityConsumed" int4 NOT NULL,
	"ConsumedBy" int4 NULL,
	"CreatedDate" timestamp NULL,
	"ReasonForConsumption" varchar(300) NULL,
	"CreatedBy" int4 NULL,
	"QuantityBeforeConsumption" int
);
